package com.Lixiaoqian.Gulangyu.view

import android.content.Context
import android.util.AttributeSet
import android.view.View
import android.widget.FrameLayout
import com.Lixiaoqian.Gulangyu.R
import kotlinx.android.synthetic.main.layout_toolbar.view.*

/**
 * Created by huangzhibo on 2018-02-26.
 * mail:1043202454@qq.com
 */
class ToolTitleBar(context: Context?, attrs: AttributeSet?) : FrameLayout(context, attrs),View.OnClickListener {
    lateinit var listener:ClickCall
    override fun onClick(view: View?) {
        when(view?.id){
            R.id.wd_bar_left->
                    listener.click(0)
            R.id.wd_bar_right->
                    listener.click(1)
        }
    }

    init {
        View.inflate(context, R.layout.layout_toolbar,this)
    }

    override fun onFinishInflate() {
        super.onFinishInflate()
        wd_bar_left.setOnClickListener(this)
        wd_bar_right.setOnClickListener(this)
    }

   fun setTitle(title:String){
       wd_bar_title.text=title
   }

    fun setLeftImage(imgRes :Int){
        wd_bar_left.setImageResource(imgRes)
    }

    fun setRightImage(imgRes:Int){
        wd_bar_right.setImageResource(imgRes)
    }

    fun isShowToolBar(isShow:Int){
        this.visibility=isShow
    }

    fun isShowLeftAndRightImage(isLeft:Int,isRight:Int){
        wd_bar_left.visibility=isLeft
        wd_bar_right.visibility=isRight
    }

    fun setCallClick(listener:ClickCall){
        this.listener=listener
    }
    interface ClickCall{
        fun click(position:Int)
    }
}